<?php

  namespace Admin\Controller;
  use Think\Controller;

  class GzjxtController extends Controller

  {

  	public function index()

  	{

       // 实例化model类
      $model = M('gzjxt');
      $data = $model->select();
      $this->assign('data',$data);
      $this->display();

  	}

   public function upload()

   {
      // dump($_FILES);
     // 实例化
     $photo = M('gzjxt');
     $data = I('post.');
     //  dump($data);


     // 实例化文件上传类
    $config = array(

        'rootPath' => 'Public/',        
        'maxSize'    =>    3145728,  
        'savePath'   =>    './Public/Uploads/', 
        'saveName'   =>    array('uniqid',''),   
        'exts'       =>    array('jpg', 'gif', 'png', 'jpeg'), 
       'autoSub'    =>    true,   
       'subName'    =>    array('date','Ymd'),

      );

    $upload = new \Think\Upload($config);

    // 2.执行文件上传操作(单文件上传)
    $info = $upload->uploadOne($_FILES['photo']);

    // dump($info);
   
    // 判断文件上传是否成功
    if($info){
         
         $data['photo'] = $info['savepath'].$info['savename'];

    }else{

         echo $upload->getError();
    }
   
          // dump($data);

    $result =  $photo->add($data);

   // dump($result);

    if($result){

          $this->success('添加成功',U('Gzjxt/index'),3);
    }else{

         $this->error('添加失败');
    }

   }

     public function find()

     {
        $model = M('gzjxt');
        $data  = $model->find(I('get.id'));
        $this->assign('data',$data);
        $this->display('Gzjxt/update');
     }

   public function update()

   {
      
     $photo = M('gzjxt');
     $data = I('post.');
      // dump($data);


     // 实例化文件上传类
    $config = array(

        'rootPath'   => 'Public/',        
        'maxSize'    =>    3145728,  
        'savePath'   =>    './Public/Uploads/', 
        'saveName'   =>    array('uniqid',''),   
        'exts'       =>    array('jpg', 'gif', 'png', 'jpeg'), 
       'autoSub'     =>    true,   
       'subName'     =>    array('date','Ymd'),

      );

    $upload = new \Think\Upload($config);

    // 2.执行文件上传操作(单文件上传)
    $info = $upload->uploadOne($_FILES['photo']);

    // dump($info);
   
    // 判断文件上传是否成功
    if($info){
         
         $data['photo'] = $info['savepath'].$info['savename'];

    }else{

        // echo $upload->getError();
    }
   
          // dump($data);

    $result =  $photo->save($data);

   // dump($result);

    if($result){

           $this->success('修改成功',U('Gzjxt/index'),3);
    }else{

         $this->error('修改失败');
    }


      
   }


   public function destroy(){

     $model=M('gzjxt');
         
      $id=I('get.id');

      $data['status']=0;

      $result = $model->where('id='.$id)->save($data);
        
       
    if($result){

          $this->success('修改成功',U('Gzjxt/index'),3);
    }else{

         $this->error('修改失败');
    }

  }

   public function qi(){

     $model=M('gzjxt');
         
      $id=I('get.id');

      $data['status']=1;

      $result = $model->where('id='.$id)->save($data);
        
       
    if($result){

          $this->success('修改成功',U('Gzjxt/index'),3);
    }else{

         $this->error('修改失败');
    }    




   }
    



}
